package com.clwl.supervise.superviseapp.service.inspect;


import com.baomidou.dynamic.datasource.annotation.DS;
import com.clwl.supervise.superviseapp.entity.base.CommonSearchEntity;
import com.clwl.supervise.superviseapp.mapper.base.TcCompanyMapper;
import com.clwl.supervise.superviseapp.mapper.supervise.AdsTsYgsbhgxxMapper;
import com.clwl.supervise.superviseapp.util.UserHelper;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;
import java.util.Map;

@Service
public class SpotCheckService {


    @Resource
    private AdsTsYgsbhgxxMapper adsTsYgsbhgxxMapper;

    @Resource
    private TcCompanyMapper companyMapper;

    /**
     * 获取抽样列表信息
     * @param pageNum 当前页数
     * @param pageSize 每页数据数量
     * @return
     */
    @DS("ads")
    public List<Map<String, Object>> selectPage(Integer pageNum, Integer pageSize, CommonSearchEntity commonSearchEntity) {
        Long userId = UserHelper.getUserId();
        commonSearchEntity.setUserId(userId);
        commonSearchEntity.setDataRange(UserHelper.getUserInfo().getDataRange());
        commonSearchEntity.setDeptId(UserHelper.getUserInfo().getDeptId());
        pageNum = pageNum  == 0 ? 0 : pageNum -1;
        int  start =  pageNum * pageSize;
        int  end = (pageNum + 1 ) * pageSize;
        return adsTsYgsbhgxxMapper.selectMapPage(start,end,commonSearchEntity);
    }


    public Map<String, Object> spotCheckGetCompany(String xkzbh, String yyzzh) {
        return companyMapper.selectByCredit( xkzbh, yyzzh);
    }
}
